package com.fxsh168.server.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created by hasee on 2016/10/24.
 */
public class SaveImg {

    public  static String getImg(Context context){
        InputStream is = context.getClass().getClassLoader().getResourceAsStream("assets/" + "picture.png");
        Bitmap bitmap = BitmapFactory.decodeStream(is);

        FileOutputStream b = null;
        File mFile = new File("/sdcard/ssimg/");
        if (!mFile.exists()) {
            mFile.mkdirs();// 创建文件夹
        }

        //文件路径
        String mFileNamePath = "/sdcard/ssimg/" + System.currentTimeMillis() + ".png";
        //文件名
        String mComplaintImgName = GetLastZF.getLatZF(mFileNamePath, "/");
        try {
            b = new FileOutputStream(mFileNamePath);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, b);// 把数据写入文件
            return mFileNamePath;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } finally {
            try {
                b.flush();
                b.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}
